/*
perone_avl - An AVL Search Tree algorithm jitter
Copyright (C) 2009 Christian S. Perone <christian.perone@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#if !defined(__PERONE_AVL_H)
#define __PERONE_AVL_H

#include <glib.h>

#include <llvm-c/Core.h>  
#include <llvm-c/BitWriter.h>
#include <llvm-c/Analysis.h>  
#include <llvm-c/ExecutionEngine.h>  
#include <llvm-c/Target.h>  
#include <llvm-c/Transforms/Scalar.h>
#include <llvm-c/Transforms/IPO.h>

#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <time.h>
#include <assert.h>

/*
   These node types are hide in GLib, so we need
   to declare. It's an opaque type in normal GLib API.
*/

typedef struct _GTreeNode  GTreeNode;

struct _GTree
{
  GTreeNode        *root;
  GCompareDataFunc  key_compare;
  GDestroyNotify    key_destroy_func;
  GDestroyNotify    value_destroy_func;
  gpointer          key_compare_data;
  guint             nnodes;
  gint              ref_count;
};

struct _GTreeNode
{
  gpointer   key;         /* key for this node */
  gpointer   value;       /* value stored at this node */
  GTreeNode *left;        /* left subtree */
  GTreeNode *right;       /* right subtree */
  gint8      balance;     /* height (left) - height (right) */
  guint8     left_child;  
  guint8     right_child;
};

typedef int (*jit_avl_lookup_t)(int) /*__attribute__((fastcall))*/;

#endif

